﻿#coding=utf-8
from django.http import HttpResponse
from django.shortcuts import render_to_response
from handle import *
from forms import *

def attention(request):
	if request.method == 'POST':
		RequestInfo=request.POST
		idx=RequestInfo['idx']
		form=article(RequestInfo)
		labelInfo=GetLabel(2)
		from django.forms import widgets
		form.fields['label'].widget=widgets.Select(choices=labelInfo)
		if form.is_valid():
			OneArtical=form.cleaned_data
			newid=SaveArtical(idx,OneArtical)
			mytitle,content=GetContent(newid)
			return render_to_response('attention_article.html',{'idx':newid,'mytitle':mytitle,'content':content})
		else:
			return render_to_response('attention_add.html',{'form': form})
	labelInfo=GetLabel()
	return render_to_response('attention.html',{'labelinfo':labelInfo})
		
def attent_article(request,idx):
	mytitle,content=GetContent(idx)
	return render_to_response('attention_article.html',{'idx':idx,'mytitle':mytitle,'content':content})
		
def attent_body(request):
	try:
		labelname=request.POST['labelname']
	except:
		labelname='-1'
	TitleInfo=GetTitle(labelname)
	return render_to_response('attention_title.html',{'titleinfo':TitleInfo})
		
def attent_body_search(request):
	searchInfo=request.POST['searchinfo']
	TitleInfo=GetTitle_search(searchInfo)
	return render_to_response('attention_title.html',{'titleinfo':TitleInfo})
		
def attent_add(request):
	form=article()
	labelInfo=GetLabel(2)
	from django.forms import widgets
	form.fields['label'].widget=widgets.Select(choices=labelInfo)
	return render_to_response('attention_add.html',{'form': form,'idx':0})
		
def attent_modify(request):
	idx=request.GET['idx']
	OneArtical=GetArtical(idx)
	form = article(initial=OneArtical)
	labelInfo=GetLabel(2)
	from django.forms import widgets
	form.fields['label'].widget=widgets.Select(choices=labelInfo)
	return render_to_response('attention_add.html',{'form': form,'idx':idx})
		
def attent_del(request):
	idx=request.GET['idx']
	DelArtical(idx)
	labelInfo=GetLabel()
	return render_to_response('attention.html',{'labelinfo':labelInfo})